Telegram Group & Telegram Channel
💬 DFS vs BFS на Python

Если хотите разобраться, как алгоритмы поиска в глубину и поиска в ширину работают на практике, то вот минимальный пример, который покажет разницу.

graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}

def dfs(node, visited=set()):
if node in visited: return
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(neighbor, visited)

def bfs(start):
queue = [start]
visited = set()
while queue:
node = queue.pop(0)
if node in visited: continue
print(node)
visited.add(node)
queue += graph[node]


➡️ Что делает

— dfs проходит глубоко: A → B → D → E → C → F
— bfs — по уровням: A → B → C → D → E → F
— Обе функции показывают порядок обхода графа

🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/proglib_academy/2787
Create:
Last Update:

💬 DFS vs BFS на Python

Если хотите разобраться, как алгоритмы поиска в глубину и поиска в ширину работают на практике, то вот минимальный пример, который покажет разницу.

graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}

def dfs(node, visited=set()):
if node in visited: return
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(neighbor, visited)

def bfs(start):
queue = [start]
visited = set()
while queue:
node = queue.pop(0)
if node in visited: continue
print(node)
visited.add(node)
queue += graph[node]


➡️ Что делает

— dfs проходит глубоко: A → B → D → E → C → F
— bfs — по уровням: A → B → C → D → E → F
— Обе функции показывают порядок обхода графа

🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст

BY Proglib.academy | IT-курсы




Share with your friend now:
tg-me.com/proglib_academy/2787

View MORE
Open in Telegram


Proglib academy | IT курсы Telegram | DID YOU KNOW?

Date: |

At a time when the Indian stock market is peaking and has rallied immensely compared to global markets, there are companies that have not performed in the last 10 years. These are definitely a minor portion of the market considering there are hundreds of stocks that have turned multibagger since 2020. What went wrong with these stocks? Reasons vary from corporate governance, sectoral weakness, company specific and so on. But the more important question is, are these stocks worth buying?

However, analysts are positive on the stock now. “We have seen a huge downside movement in the stock due to the central electricity regulatory commission’s (CERC) order that seems to be negative from 2014-15 onwards but we cannot take a linear negative view on the stock and further downside movement on the stock is unlikely. Currently stock is underpriced. Investors can bet on it for a longer horizon," said Vivek Gupta, director research at CapitalVia Global Research.

Proglib academy | IT курсы from ms


Telegram Proglib.academy | IT-курсы
FROM USA